# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Baptiste Jonglez <archlinux at bitsofnetworks.org>
# Contributor: Christian Hesse <mail@eworm.de>
# Contributor: Andreas Wagner <andreas.wagner@lowfatcomputing.org>
# Contributor: Jeff Mickey <jeff@archlinux.org>

pkgname=icmake
pkgver=10.03.03
pkgrel=1
pkgdesc='A program maintenance (make) utility using a C-like grammar'
arch=('loong64' 'x86_64')
url='https://fbb-git.gitlab.io/icmake/'
license=('GPL3')
source=("https://gitlab.com/fbb-git/${pkgname}/-/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz"
        'disable-clear-screen.patch')
b2sums=('4711dee5d66882afeeb6e7206b97341690e2e1c0e511fcf9f43d41ec04bec2ecf5fee10113bba47475b3166dc8dc53f7b236c42dcf0969582a59bbf30b7ca618'
        '6689ce74a985742e079f95bfaa22dcee22ad667f45cf21f79d4c3d2271f925f53bcd6729ca762a7cfa6a63af9b0fd48c2b9c024bd35ca580e83a6a54758a7bed')
makedepends=('icmake' 'yodl')
depends=('libbobcat' 'libunwind')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgver}"
    patch -Np1 -i "${srcdir}/disable-clear-screen.patch"

    # fix paths
    sed -i 's|usr/libexec/icmake|usr/lib/icmake|' icmake/INSTALL.im

    # for some reason we have to do this
    sed -e '/verbinclude(\/home\/frank\/.icmake\/AUTHOR)/d' -i icmake/doc/manpage/icmconf.yo
    export AUTHOR="Frank B. Brokken (f.b.brokken@rug.nl)"
    echo "${AUTHOR}" > AUTHOR
}

build() {
    cd "${srcdir}/${pkgname}-${pkgver}"
    # when upgrading to new SONAME, remove ./manpages from HOME variable
    # to allow compiling the package without invoiking icmake itself
    HOME=./ ./manpages

    cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

    export CXXFLAGS="${CXXFLAGS} -Wp,-U_GLIBCXX_ASSERTIONS -std=c++20"

    ./icm_prepare /
    ./icm_bootstrap /
}

package() {
    cd "${srcdir}/${pkgname}-${pkgver}/${pkgname}"

    ./icm_install all "${pkgdir}"
}
